<!DOCTYPE html>
<head >
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta charset="utf-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<link rel="stylesheet" href="../../../layuiadmin/layui/css/layui.css"  media="all"/>
<link rel="stylesheet" href="../../../layuiadmin/style/admin.css" media="all"/>
<link rel="stylesheet"  href="../../../css/common/loader.css" media="all"/>
<link rel="stylesheet"  href="../../../css/common/tablepage.css" media="all"/>
</head>
<body>
	<div class="layui-fluid">
		<div class="layui-card">
			<div class="layui-form layui-card-header layuiadmin-card-header-auto" id="searchForm">
			   <div class="layui-form-item">

                 <div class="layui-inline">
				  <label class="layui-form-label">应用名称</label>
				  <div class="layui-input-block">
				  <input type="text" name="appName" autocomplete="off" class="layui-input">
				   </div>
				 </div>
                 <div class="layui-inline">
				  <label class="layui-form-label">联系人</label>
				  <div class="layui-input-block">
				  <input type="text" name="linkMan" autocomplete="off" class="layui-input">
				   </div>
				 </div>
                 <div class="layui-inline">
						<label class="layui-form-label">当前状态</label>
						<div class="layui-input-block">
							<select name="status" lay-select-dict="status" >
								
							</select>
						</div>
				</div>
                
				 <div class="layui-inline">
				  <button class="layui-btn layuiadmin-btn-sm" lay-submit
							lay-filter="searchSubmit"  >查询</button>
				</div>
				</div>
			</div>
			<div class="layui-card-body">
				<table id="dataList" lay-filter="dataList" ></table>
				
	
			</div>
		</div>
	</div>
<div type="text/html" id="trTool" style="display:none">
    <a  data-grant="system:appConfig:edit" class="layui-btn layui-btn-normal layui-btn-xs" lay-event="edit"><i class="layui-icon layui-icon-edit"></i>编辑</a>
     <a data-grant="system:appConfig:resetAccount" class="layui-btn layui-btn-blue layui-btn-xs" lay-event="resetAccount"> <i class="layui-icon">&#xe669;</i>重置账号</button>
    <a  data-grant="system:appConfig:remove" class="layui-btn layui-btn-danger layui-btn-xs" lay-event="remove"><i class="layui-icon layui-icon-delete"></i>删除</a>
</div>

<div type="text/html" id="toolbar" style="display:none" >
<div class="layui-btn-container">
     <button data-grant="system:appConfig:add"   class="layui-btn layui-btn-sm" lay-event="add"> <i class="layui-icon layui-icon-add-1"></i>新增</button>
</div>
</div>
<script type="text/html" id="statusTpl">
  
  <input type="checkbox" name="status"  value="{{d.configId}}" title="启用" lay-filter="status" {{ d.status == '1' ? 'checked' : '' }}>
</script>
<script type="text/html" id="editModeTpl">
  <input type="checkbox" name="editMode" value="{{d.configId}}"  lay-skin="switch" lay-text="可编辑|只读" lay-filter="editMode" {{ d.editMode == '1' ? 'checked' : '' }}>
</script>
<script   src="../../../layuiadmin/layui/layui.js"></script>
<script type="text/javascript" src="../../../lib/jQuery-2.2.0.min.js" ></script>
	<script>
		layui.config({
			base :  '../../../layuiadmin/' //静态资源所在路径
		}).extend({
			webplus : 'lib/webplus'//主入口模块
			
		}).use([ 'table','form','webplus' ], function() {
			var $ = layui.$,
			webplus=layui.webplus,
			form = layui.form,
			table = layui.table;
		   var cols= [ [ {
				type : 'numbers',
				title : '序号'
			}, {
				field : 'configId',
				title : '编号',
				hide : true 
			},
            {
			 field : 'appName',
			 title : '应用名称',
			 width:200
			},
            {
			 field : 'accessKey',
			 title : '应用账号',
			 width:280
			},
            {
			 field : 'secretKey',
			 title : '应用秘钥',
			 width:110
			},
            {
			 field : 'linkMan',
			 title : '联系人',
			 width:100
			},
            {
			 field : 'phone',
			 title : '联系电话',
			 width:120
			},
          
			{
				field : 'status_dict',
				title : '当前状态',
				templet: '#statusTpl', 
				unresize: true,
				width : 110
			}, {
				field : 'editMode_dict',
				title : '编辑模式',
				templet: '#editModeTpl', 
				unresize: true,
				width : 110
			},
            {
			 field : 'updateTime',
			 title : '最后更新时间',
			 width:180
			},
            
           {

				title : '操作',
				toolbar : '#trTool',
				fixed: 'right',
				width :240
			} ] ];
		   webplus.init('system/appConfig/list',cols)
		    var rowObj;
		     //行单击事件
			  table.on('row(dataList)', function(obj){
				  obj.tr.addClass('layui-table-click').siblings().removeClass('layui-table-click');
				     rowObj=obj;
			     });
		      //监听启用操作
			  form.on('checkbox(status)', function(obj){
				  
				  if(webplus.checkFormEditMode(obj)){
					  var status="0";
			    	   if(obj.elem.checked){
			    		   status="1";
			    	   }
			    	   
			    	   var configId=obj.value;
			    	   var params={};
			    	   params.configId=configId;
			    	   params.status=status;
			    	   webplus.doAjax("system/appConfig/update",params,"","0");
				  }
				 
			  });
			 
			  //监听启用操作
			  form.on('switch(editMode)', function(obj){
				  if(webplus.checkFormEditMode(obj)){
					  var editMode="0";
			    	   if(obj.elem.checked){
			    		   editMode="1";
			    	   }
			    	   
			    	   var params={};
			    	   params.configId=obj.value;
			    	   params.editMode=editMode;
			    	   webplus.doAjax("system/appConfig/update",params,"","","3",function(data){
			    		   rowObj.update({editMode:editMode});
			    	   }); 
				  }
					 
			  });
			 //监听行工具事件
			  table.on('tool(dataList)', function(rowObj){
			    switch(rowObj.event){
			    	case 'edit':
			    		if(webplus.checkRowEditMode(rowObj)){
			    			webplus.openEditWindow('editAppConfig.html','编辑',rowObj,'configId','','700','400');
			    		}
			       		
			   			break;
			    	case 'resetAccount':
			    		if(webplus.checkRowEditMode(rowObj)){
			    			webplus.doAjax('system/appConfig/resetAccount',{configId:rowObj.data.configId},'你确定重置该应用的账号和秘钥吗？','', '0',)
			    		}
			       		
			   			break;
			    	case 'remove':
			    		if(webplus.checkRowEditMode(rowObj)){
			    			 webplus.removeRow('system/appConfig/remove',rowObj,'configId');
			    		}
				       
			    		break;
			    }
			  });
			 //监听表头按钮事件
			  table.on('toolbar(dataList)', function(obj){
			    switch(obj.event){
			      	case 'add':
				         //打开添加弹出框
				         webplus.openWindow('addAppConfig.html','新增','700','400');
			     	     break;
			    }
			  });

		});
	</script>

</body>
</html>